<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Music/classes/PhpFox_ComponentViewSong.class.php, $Author:  $ */



/** Component for viewing song
 *
 * @version $Id: PhpFox_ComponentViewSong.class.php 474 2008-07-30 08:52:54Z phpfoxsv $
 * @package module.music
 */
class PhpFox_Mod_Music_ComponentViewSong extends BaseComponent
{
    function process()
    {
        $oMusicService = &$this->_oModule->getService('Music');
        /* @var $oMusicService PhpFox_Mod_Music_ServiceMusic */
        $oSecurityService = &App::getModuleService('Account', 'Security');
        /* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
        $oReq = &App::getRequest();
        $oTpl = &$this->_oModule->getTemplate();

        $oSecurityService->checkPerm('music', array('read_only', 'full'));
        $oSecurityService->checkAccess('music');
        $iSongId = $oReq->getInt('id');
        $aCond = array
        (
            'song_id' => '= '.$iSongId,
        );
        list($aSong, $iCnt) = $oMusicService->getSongsList($aCond);
        if (!count($aSong))
        {
            App::gotoUrl('public.music');
        }
        $aSong = $aSong[0];
        if (!$aSong['song_is_approved'])
        {
            App::gotoUrl('public.music');
        }
        $bStaff = $oSecurityService->isStaff();
        if ($oReq->get('delete'))
        {
            if ($bStaff)
            {
                $oMusicService->deleteSong($iSongId);
            }
            App::gotoUrl('public.music');
        }
        if ($oReq->get('makefavorite'))
        {
            if ($oMusicService->makeSongFavorite($iSongId))
            {
                App::gotoUrl('public.account.favorites');
            }
            App::gotoUrl();
        }
        if ($oReq->get('feature'))
        {
            if ($bStaff)
            {
                $oMusicService->setSongFeaturedState($iSongId, true);
            }
            $oUrl = &App::getUrl();
            $oUrl->clearParams('feature');
            App::forward($oUrl->getUrl());
        }
        if ($oReq->get('unfeature'))
        {
            if ($bStaff)
            {
                $oMusicService->setSongFeaturedState($iSongId, false);
            }
            $oUrl = &App::getUrl();
            $oUrl->clearParams('unfeature');
            App::forward($oUrl->getUrl());
        }
        if ($oReq->get('makeaccount'))
        {
            $oMusicService->setActualAccountMusic($iSongId);
            App::gotoUrl('', array('id' => $iSongId));
        }
	$oMusicService->makeSongPlayed($iSongId);
        $oUser = App::loadUser();
        $aSong['song_is_favorite'] = $oMusicService->isSongFavorite($iSongId);
        $aSong['song_is_actual']   = $oMusicService->isSongActual($iSongId);
        $aSong['song_owner'] 	   = ($aSong['user_id'] == App::getUser('id') ? true : false);

        $oCurrUser = $oSecurityService->getCurrentUser();
		App::setAccessForContent('music', $iSongId);
		
        $oTpl->assign(array(
            'aSong'     => $aSong,
            'bStaff'    => $bStaff,
            'oCurrUser' => $oCurrUser,
            'iCnt' => $iCnt
        ));
        return $oTpl->fetch('PlaySong.html');
    }
}
?>